﻿#pragma once


#include <QDialog>
#include <QPushButton>
#include "QListView"
#include "QStringListModel"
#include "QFileDialog"
#include "QMessageBox"
#include "QApplication"
#include "QVBoxLayout"
#include <QDesktopWidget>
#include <QLabel>
#include <QComboBox>
#include "QSpinBox"
#include <QSettings>

#include "commonfunction.h"

#include "halcon_opencv.h"

using namespace std;

#include "qt_graphics_view_image.h"


#include "function_dl_3.h"
#include "function_dl.h"
#include "function_frank_match.h"
#include "function_bottom_match.h"
#include "function_dump.h"
#include "function_width_measure.h"
#include "function_circle_match.h"
#include "function_segment_circle.h"
#include "function_segment_rect.h"
#include "function_find_shape_model.h"
#include "function_frank_width.h"

#include <QSettings>

class Function:public QDialog
{
public:
    QSettings* m_qsettings;

	int m_camera_index = 0;
   
	QString m_dir = "";
	
    
    QString m_model_image_path = "model.png";


    FunctionDump* m_function_dump = nullptr;
    QPushButton* m_pushbutton_dump = nullptr;
    QComboBox* m_qcombobox_unuse_use_dump = nullptr;
    int m_unuse_use_dump = 0;

	FunctionWidthMeasure* m_function_width_measure = nullptr;
	QPushButton* m_pushbutton_width_measure = nullptr;
	QComboBox* m_qcombobox_unuse_use_width_measure = nullptr;
	int m_unuse_use_width_measure = 0;

    FunctionFrankWidth* m_function_frank_width = nullptr;
    QPushButton* m_pushbutton_frank_width = nullptr;
    QComboBox* m_qcombobox_unuse_use_frank_width = nullptr;
    int m_unuse_use_frank_width = 0;




    FunctionCircleMatch* m_function_circle = nullptr;
    QPushButton* m_pushbutton_circle = nullptr;
    QComboBox* m_qcombobox_unuse_use_circle = nullptr;
    int m_unuse_use_circle = 0;

    FunctionFindShapeModel* m_function_find_shape_model = nullptr;
    QPushButton* m_pushbutton_find_shape_model = nullptr;
    QComboBox* m_qcombobox_unuse_use_find_shape_model = nullptr;
    int m_unuse_use_find_shape_model = 0;


    

    Mat m_image ;

    QString m_section   = "";
    QtQGraphicsView* m_view ;
    QGraphicsPixmapItem* pixmapItem;

    QPushButton* m_pushbutton_load_image;
    QPushButton* m_pushbutton_load_dir;
    QListView* m_listview;
    QStringListModel* m_listview_model;



    Mat image_out;

	FunctionDL* m_dl_halcon=nullptr;
	QPushButton* m_pushbutton_dl_halcon = nullptr;
	QComboBox* m_qcombobox_unuse_use_dl_halcon = nullptr;
	int m_unuse_use_dl_halcon=0;


    int m_dl_times=1;
    vector<Function_dl_3*> m_vector_dl;
    vector<QPushButton*> m_vector_pushbutton_dl;
    vector<QComboBox*> m_vector_qcombobox_unuse_use_dl;
    vector<int> m_vector_unuse_use_dl;

    vector<FunctionSegmentCircle*> m_vector_segment_circle;
    vector<QPushButton*> m_vector_pushbutton_segment_circle;
    vector<QComboBox*> m_vector_qcombobox_unuse_use_segment_circle;
    vector<int> m_vector_unuse_use_segment_circle;

	vector<FunctionSegmentRect*> m_vector_segment_rect;
	vector<QPushButton*> m_vector_pushbutton_segment_rect;
	vector<QComboBox*> m_vector_qcombobox_unuse_use_segment_rect;
	vector<int> m_vector_unuse_use_segment_rect;

	DetectionFrankMatch* m_function_frank_match = nullptr;
    QPushButton* m_pushbutton_frank_match = nullptr;
    QComboBox* m_qcombobox_unuse_use_frank_match = nullptr;
    int m_unuse_use_frank_match = 0;

    DetectionBottomMatch* m_function_bottom_match = nullptr;
    QPushButton* m_pushbutton_bottom_match = nullptr;
    QComboBox* m_qcombobox_unuse_use_bottom_match = nullptr;
    int m_unuse_use_bottom_match = 0;


    //QComboBox* m_qcombobox_save_wrong;
    int m_save_wrong = 1;

    ////QComboBox* m_qcombobox_save_right;
    int m_save_right = 1;


    //QComboBox* m_qcombobox_save_wrong_label=nullptr;
    int m_save_wrong_label = 1;

    //QComboBox* m_qcombobox_save_ai_ok = nullptr;
    int m_save_ai_ok = 1;

    //QComboBox* m_qcombobox_save_ai_ng;
    int m_save_ai_ng = 1;

    QPushButton* m_pushbutton_save_load_image;
	QPushButton* m_pushbutton_show_orign_image;
    QPushButton* m_pushbutton_detection;
    QPushButton* m_pushbutton_save_parameter;
    QPushButton* m_pushbutton_return;
	QPushButton* m_pushbutton_on_off;
	bool  m_on_off = true;

	QLabel*    m_qlabel_index;
	QComboBox* m_qcombobox_index=nullptr;
	


    Mat m_image_show;

   

    int m_result;
    vector<int> m_vector_error_column;
    vector<int> m_vector_error_row;
public:
    explicit Function(QDialog* parent, QString dir, int camera_index);


    bool detection(HObject image_in, int index,QString& message);

    
    void detectionImage();

    
    void draw(Mat image_in,int index, Mat& image_out);

    
    void getDeeplearingImage(Mat image_in,int index, Mat& image_out)
    {
        if(index<m_dl_times)
        {
            if (m_vector_unuse_use_dl[index] && m_vector_dl[index] != nullptr)
            {
                image_out = m_vector_dl[index]->m_image;
            }
            else
            {
                image_out = image_in;
            }
        }

    }
    void listViewClick(const QModelIndex& model_index);

    void loadParameter();


    void saveParameter();

    
    bool showDialog();

};
#pragma execution_character_set("utf-8")
